package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.InventoryInfoBean;
import com.project.bean.RecordBean;
import com.project.mapper.IRecordMapper;
import com.project.service.IRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class RecordServiceImpl implements IRecordService {
    @Autowired
    private IRecordMapper IRecordMapper;

    @Override
    public IPage<RecordBean> findRecordAll(int pageNO, String status) {
        QueryWrapper<RecordBean> qw = new QueryWrapper<>();
        if (status != null && status.length() != 0) {
            qw.eq("status", status);
        }
        return IRecordMapper.selectPage(new Page<>(pageNO,3),qw);
    }

    @Override
    public boolean addInRecord(InventoryInfoBean inventoryInfoBean, Integer num, String state) {
        if (inventoryInfoBean != null){
            RecordBean recordBean = new RecordBean();
            //商品编号
            recordBean.setCommodityId(inventoryInfoBean.getProductId());
            //记录数量
            recordBean.setCommodityNum(num);
            //记录商品名
            recordBean.setCommodityName(inventoryInfoBean.getProductName());
            //记录状态
            recordBean.setStatus(state);
            //记录颜色
            recordBean.setColor(inventoryInfoBean.getColor());
            //记录大小
            recordBean.setSize(inventoryInfoBean.getSize());

            IRecordMapper.insert(recordBean);
        }
        return false;
    }
}
